package fr.pud.client.controller.address;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;

import org.openstreetmap.gui.jmapviewer.Coordinate;

import fr.pud.client.i18n.LanguagesConstants;
import fr.pud.client.images.ImagesDatabase;
import fr.pud.client.model.PUDStation;
import fr.pud.client.model.SuggestionAddresses;
import fr.pud.client.view.JMapViewerExtended;

/**
 * The class which enables to move the map from the current point to the
 * targetted point.
 * Apr 8, 2012 - OSE
 * @author Simon Devineau, Adrien Hierry, Leopold Houdin, Pierre Reliquet
 *         Ecole des Mines de Nantes
 *         GoToAddressButton.java
 */
public class GoToAddressButton extends AbstractAction {
    /**
     * The serial uid
     */
    private static final long serialVersionUID = 6339686432606855248L;
    /**
     * The coordinate which is targetted
     */
    private Coordinate        coordinate;

    /**
     * The constructor which sets up the GUI.
     * @param aCoordinate
     *            , the coordinate to go to.
     */
    public GoToAddressButton(Coordinate aCoordinate) {
        this.putValue(NAME,
                LanguagesConstants.LANGUAGE.getString(LanguagesConstants.GO_TO));
        this.putValue(SMALL_ICON, ImagesDatabase.GO_TO);
        this.putValue(SHORT_DESCRIPTION, LanguagesConstants.LANGUAGE
                .getString(LanguagesConstants.GO_TO_DESCRIPTION));
        this.coordinate = aCoordinate;
    }

    /**
     * Moves the map.
     */
    @Override
    public void actionPerformed(ActionEvent arg0) {
        if (this.getCoordinate().getLat() != 0.0
                && this.getCoordinate().getLon() != 0.0) {
            System.out.println(SuggestionAddresses.getSuggestionAddresses());
            SuggestionAddresses.getSuggestionAddresses().addSuggestionPUD(
                    new PUDStation(this.getCoordinate()));
            JMapViewerExtended.getJMapViewer().MoveMapToCenter(
                    this.getCoordinate());
            System.out.println(SuggestionAddresses.getSuggestionAddresses());
        }
    }

    /**
     * @return the coordinate
     */
    public Coordinate getCoordinate() {
        return this.coordinate;
    }
}
